package com.king.login.controller;

import com.king.login.entity.SystemUser;
import com.king.login.param.SystemUserParam;
import com.king.login.service.SystemUserService;
import com.king.platform.dto.PageDTO;
import com.king.platform.enmu.ResultEnum;
import com.king.platform.entity.BaseResult;
import com.king.platform.exception.BizException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>todo SystemUser 表控制器</p>
 * @author: cuizx
 * @created: 2024-05-10 11:48:49
 * @version v1.0.1
 * @copyright: Copyright (c)  cuizx
 */

@Tag(name="systemUser-api")
@RestController
@RequestMapping("/systemUser")
public class SystemUserController {

    @Autowired
    private SystemUserService systemUserService;

    /**
     * <p>todo 查询所有</p>
     * @param: model
     * @return: SystemUser
     * @author: cuizx
     * @date: 2024-05-10 11:48:49
     * @version: 1.0.1
     * Modification History:
     * Date         Author          Version            Description
     * -----------------------------------------------------------
     * 2024-05-10 11:48:49    cuizx        v1.0.1             init
     */
    @PostMapping("/list")
    @Operation( summary= "查询所有",description = "查询所有")
    public BaseResult<List<SystemUser>> list(@RequestBody SystemUserParam model) {
        
       //执行查询
        List<SystemUser> list = systemUserService.list(model);
        //封装查询结果
        return BaseResult.success(ResultEnum.SUCCESS_CODE,list);
    }
    
    /**
     * <p>todo 分页查询</p>
     * @param: model
     * @return: SystemUser
     * @author: cuizx
     * @date: 2024-05-10 11:48:49
     * @version: 1.0.1
     * Modification History:
     * Date         Author          Version            Description
     * -----------------------------------------------------------
     * 2024-05-10 11:48:49    cuizx        v1.0.1             init
     */
    @PostMapping("/listPage")
    @Operation( summary= "分页查询",description = "分页查询")
    public BaseResult<PageDTO<SystemUser>> listPage(@RequestBody SystemUserParam model) {
        
        //执行查询
        PageDTO<SystemUser> pageInfo = systemUserService.listPage(model);
        
        //封装查询结果
        return BaseResult.success(ResultEnum.SUCCESS_CODE,pageInfo);
        }
    
   /**
     * <p>todo 保存</p>
     * @param: model
     * @return: SystemUser
     * @author: cuizx
     * @date: 2024-05-10 11:48:49
     * @version: 1.0.1
     * Modification History:
     * Date         Author          Version            Description
     * -----------------------------------------------------------
     * 2024-05-10 11:48:49    cuizx        v1.0.1             init
     */
   @PostMapping("/insert")
   @Operation( summary= "保存",description = "保存")
    public BaseResult insert(@RequestBody SystemUser model) {
        
        systemUserService.save(model);
        //封装查询结果
        return model.getId()>0?BaseResult.success(ResultEnum.SUCCESS_CODE):BaseResult.failed(ResultEnum.FAILED_CODE);
    }

    /**
     * <p>todo 根据id更新</p>
     * @param: model
     * @return: SystemUser
     * @author: cuizx
     * @date: 2024-05-10 11:48:49
     * @version: 1.0.1
     * Modification History:
     * Date         Author          Version            Description
     * -----------------------------------------------------------
     * 2024-05-10 11:48:49    cuizx        v1.0.1             init
     */
     @PutMapping("/updateById")
     @Operation( summary= "更新",description = "更新")
    public BaseResult updateById(@RequestBody SystemUser model) {
      
      if(model.getId()==null){
        throw new BizException(900001,"用户id不存在");
      }
        systemUserService.updateById(model);
        //封装查询结果
        return BaseResult.success(ResultEnum.SUCCESS_CODE);
    }


    /**
     * <p>todo 根据id查询</p>
     * @param: id
     * @return: SystemUser
     * @author: cuizx
     * @date: 2024-05-10 11:48:49
     * @version: 1.0.1
     * Modification History:
     * Date         Author          Version            Description
     * -----------------------------------------------------------
     * 2024-05-10 11:48:49    cuizx        v1.0.1             init
     */
    @GetMapping(value = "/getById/{id}")
    @Operation( summary= "根据id查询",description = "根据id查询")
    public BaseResult<SystemUser> getById(@PathVariable("id") Long id) {
        SystemUser temp = systemUserService.getById(id);
        //封装查询结果
       return BaseResult.success(ResultEnum.SUCCESS_CODE,temp);
    }

    /**
     * <p>todo 根据id删除</p>
     * @param: id
     * @return: SystemUser
     * @author: cuizx
     * @date: 2024-05-10 11:48:49
     * @version: 1.0.1
     * Modification History:
     * Date         Author          Version            Description
     * -----------------------------------------------------------
     * 2024-05-10 11:48:49    cuizx        v1.0.1             init
     */
    @DeleteMapping("/deleteById/{id}")
    @Operation( summary= "根据id删除",description = "根据id删除")
    public BaseResult deleteById(@PathVariable("id") Long id) {
        systemUserService.removeById(id);
        //封装查询结果
       return BaseResult.success(ResultEnum.SUCCESS_CODE);
    }

    /**
     * <p>todo 批量删除</p>
     * @param: ids
     * @return: SystemUser
     * @author: cuizx
     * @date: 2024-05-10 11:48:49
     * @version: 1.0.1
     * Modification History:
     * Date         Author          Version            Description
     * -----------------------------------------------------------
     * 2024-05-10 11:48:49    cuizx        v1.0.1             init
     */
    @DeleteMapping("/deleteByIds")
    @Operation( summary= "批量删除",description = "批量删除")
    public BaseResult deleteByIds(@RequestParam("ids") String ids) {
         if(ids==null){
        throw new BizException(900001,"用户id不存在");
      }
        systemUserService.deleteByIds(ids);
        //封装查询结果
       return BaseResult.success(ResultEnum.SUCCESS_CODE);
    }
    
    
}


